Processing orders in batches is more efficient and faster than processing them individually. However, batches can only contain orders for the same account and market, additionally revision and pull batches must only have orders for the same ExecutingLoginID. Due to load balancing performed by the servers the orders for an account may be executed by different servers and have different ExecutingLoginID’s, though a single batch of orders will be executed by a single server and ExecutingLoginID.
Additionally, not all trading exchanges support batches of orders so part of the efficiency benefit is lost.
Order updates and fills occur the same for batches as they do for single orders. However, if you use the OrderUpdate events from the Position, Account or AccountList objects instead of from the Order object then you will receive the updates in batches as well.
To submit a batch of orders you first create an
OrderList.Submission object and then add orders to it. Once the batch is complete then you can submit it.
' Reference to the batch orders.
Private moOrder1 As Order
Private moOrder2 As Order
…
' Get an account to submit the order for.
Dim oAccount As Account = moAccounts(0)
' Get a market to submit the order in.
Dim oMarket As Market = moFilter(0)
' Create the batch submission object.
Dim oBatch As OrderList.Submission
oBatch = moAccounts.SubmitOrders(oAccount, oMarket)
' Add an order to the batch.
moOrder1 = oBatch.Add(BuySell.Buy, _
PriceType.Limit, _
TimeType.Normal, _
1, _
CDbl(107000))
' Add an order to the batch.
moOrder2 = oBatch.Add(BuySell.Buy, _
PriceType.Limit, _
TimeType.Normal, _
1, _
CDbl(107010))
' Submit the batch.
oBatch.Submit()
The Add parameter details are described
here:
NOTE: If the AutoSendOnMaxSize optional parameter on the Add method is left at its default value of True then if the number of orders in the batch exceeds the maximum allowed (defined by the MaxBatchOrders property and usually 16) then the batch will be submitted as the next order is added. The batch is then emptied and the order added to what is effectively a new batch. If AutoSendOnMaxSize is set to False then the order would not be added and Nothing (null) would be returned.
To revise a batch of orders you first create an
OrderList.Revision object and add the orders to it. Once the batch is complete you can send it.
' Check to see that we have some orders.
If Not moOrder1 Is Nothing And Not moOrder2 Is Nothing Then
If moOrder1.IsWorking And moOrder2.IsWorking Then
' Create the batch revision object.
Dim oBatch As OrderList.Revision
oBatch = moAccounts.ReviseOrders(moOrder1.Account, moOrder1.Market)
' Add the order to the revision.
oBatch.AddTicks(moOrder1, 2, moOrder1.CurrentLimitTicks)
' Add the order to the revision.
oBatch.AddTicks(moOrder2, 2, moOrder2.CurrentLimitTicks)
' Revise the batch.
oBatch.Revise()
End If
End If
The Add parameter details are described
here.
To pull a batch of orders you first create an
OrderList.Pull object and add the orders to it. Once the batch is complete you can send it.
' Check to see that we have some orders.
If Not moOrder1 Is Nothing And Not moOrder2 Is Nothing Then
If moOrder1.IsWorking And moOrder2.IsWorking Then
' Create the batch pull object.
Dim oBatch As OrderList.Pull
oBatch = moAccounts.PullOrders(moOrder1.Account, moOrder1.Market)
' Add the order to the batch.
oBatch.Add(moOrder1)
' Add the order to the batch.
oBatch.Add(moOrder2)
' Pull the batch.
oBatch.Pull()
End If
End If